local xionghuo = fk.CreateSkill{
    name = "tyta__xionghuo",
}

local H = require "packages.ol_hegemony.util"

xionghuo:addEffect("active",{
    anim_type = "offensive",
    card_num = 0,
    target_num = 1,
    prompt = "#tyxionghuo-active",
    can_use = function(self, player)
      return player:getMark("@hegbaoli") > 0
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self, player, to_select, selected)
      return #selected == 0 and to_select ~= player and to_select:getMark("@hegbaoli") == 0
      and (not H.compareKingdomWith(player, to_select) and to_select.kingdom ~= "unknown")
    end,
    on_use = function(self, room, effect)
      local player = effect.from
      local target = effect.tos[1]
      room:removePlayerMark(player, "@hegbaoli", 1)
      room:addPlayerMark(target, "@hegbaoli", 1)
    end,
})

xionghuo:addEffect(fk.GeneralRevealed, {
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
      if player:hasSkill(xionghuo.name) then
        if player:usedSkillTimes(xionghuo.name, Player.HistoryGame) == 0 then
          for _, v in pairs(data) do
            if table.contains(Fk.generals[v]:getSkillNameList(), xionghuo.name) then return true end
          end
        end
      end
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
      local room = player.room
      room:addPlayerMark(player, "@hegbaoli", 3)
    end,
  })

xionghuo:addEffect(fk.DamageCaused,{
    anim_type = "offensive",
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
       return target == player and data.to ~= player and data.to:getMark("@hegbaoli") > 0 and data.to:getMark("tyta_xionghuo_damaged-turn") == 0
       and player:hasSkill(xionghuo.name) --每回合加伤一次
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:doIndicate(player.id, {data.to.id})
        data:changeDamage(1)
        room:setPlayerMark(data.to, "tyta_xionghuo_damaged-turn", 1)
     end,
})

xionghuo:addEffect(fk.EventPhaseStart,{
    anim_type = "offensive",
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
     return target ~= player and target:getMark("@hegbaoli") > 0 and target.phase == Player.Play and player:hasSkill(xionghuo.name)
   end,
    on_use = function(self, event, target, player, data)
       local room = player.room
       room:doIndicate(player.id, {target.id})
       room:removePlayerMark(target, "@hegbaoli", 1)
       local rand = math.random(1, target:isNude() and 2 or 3)
       if rand == 1 then
         room:damage {
           from = player,
           to = target,
           damage = 1,
           damageType = fk.FireDamage,
           skillName = xionghuo.name,
         }
         room:addTableMark(target, "@@tyta_xionghuo_prohibit-turn", player.id)
        elseif rand == 2 then
         room:loseHp(target, 1, xionghuo.name)
        else
         local num = #target:getCardIds("e")
         if num ~= 0 then
         local cards = room:askToChooseCard(player, {target = target, flag = "e", skill_name = xionghuo.name})
         room:moveCardTo(cards, Player.Hand, player, fk.ReasonPrey, xionghuo.name, "", false, player)
         end
         local num2 = #target:getCardIds("h")
         if num2 ~= 0 then
         local cards1 = room:askToChooseCard(player, {target = target, flag = "h", skill_name = xionghuo.name})
         room:moveCardTo(cards1, Player.Hand, player, fk.ReasonPrey, xionghuo.name, "", false, player)
         end
       end
   end,
})

xionghuo:addEffect("prohibit",{
    is_prohibited = function(self, from, to, card)
        return card.trueName == "slash" and from and table.contains(from:getTableMark("@@tyta_xionghuo_prohibit-turn") ,to.id)
    end,
})

xionghuo:addLoseEffect(function (self, player, is_death)
    for _, p in ipairs(player.room.alive_players) do
      if p:getMark("@hegbaoli") > 0 then
        player.room:setPlayerMark(p, "@hegbaoli", 0)
      end
    end
  end)


Fk:loadTranslationTable{
    ["tyta__xionghuo"] = "凶镬",
    [":tyta__xionghuo"] = "当你首次明置此武将牌时，你获得3个“暴戾”标记。出牌阶段，你可以令一名没有“暴戾”标记的与你势力不同的角色获得你的1枚“暴戾”标记；"..
    "每回合对每名角色限一次，你对有此标记的其他角色造成的伤害+1。有“暴戾”的其他角色出牌阶段开始时，移去“暴戾”标记并随机执行一项："..
    "<br>1.受到你造成的1点火焰伤害且本回合不能对你使用【杀】；"..
    "<br>2.失去1点体力且本回合手牌上限-1；"..
    "<br>3.你依次获得其装备区和手牌区内的各一张牌。",

    ["@hegbaoli"] = "暴戾",
    ["#tyxionghuo-active"] = "发动 凶镬，将“暴戾”交给其他角色",
    ["@@tyta_xionghuo_prohibit-turn"] = "凶镬1",

    ["$tyta__xionghuo1"] = "此镬加之于你，定有所伤！",
    ["$tyta__xionghuo2"] = "凶镬沿袭，怎会轻易无伤？",
}

return xionghuo